//
//  YQLoginViewController.m
//  EPA--1
//
//  Created by lanou3g on 16/4/27.
//  Copyright © 2016年 刘永庆. All rights reserved.
//

#import "YQLoginViewController.h"
#import "YQRegistViewController.h"
#import "UserInfoManager.h"
@interface YQLoginViewController ()
@property (weak, nonatomic) IBOutlet UILabel *emailLable;
@property (weak, nonatomic) IBOutlet UITextField *emailField;
@property (weak, nonatomic) IBOutlet UILabel *passWordLable;
@property (weak, nonatomic) IBOutlet UITextField *passWordField;

@end

@implementation YQLoginViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"登录";
    
}
//登录
- (IBAction)didClickLoginAction:(UIButton *)sender {
    [YQNetWorkRequestManager requestURL:[NSURL URLWithString:@"http://api2.pianke.me/user/login"] method:YQ_POST params:@{@"email":[NSString stringWithFormat:@"%@@126.com",self.emailField.text],@"passwd":self.passWordField.text} result:^(NSData *data, NSURLResponse *response, NSError *error) {
        if (data) {
            NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
            NSDictionary *dataDict = jsonDict[@"data"];
            NSString *msg = dataDict[@"msg"];
            msg = msg ? msg : @"登录成功";
            UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"提示" message:msg preferredStyle:UIAlertControllerStyleAlert];
            [alertC addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                if ([jsonDict[@"result"] isEqual:@1]) {
                    dispatch_async(dispatch_get_main_queue(), ^{
                        [self dismissViewControllerAnimated:YES completion:nil];
                    });
                }
            }]];
            dispatch_async(dispatch_get_main_queue(), ^{
                [self presentViewController:alertC animated:YES completion:nil];
            });
            if ([jsonDict[@"result"] isEqual:@1]) {
                [[UserInfoManager shareManager] loginWithUserDcit:dataDict];
//                self.userBlock([YQUserInfoManager shareManager].uname,[YQUserInfoManager shareManager].coverimg);
            }

        }
    }];
}
//注册
- (IBAction)didClickRegistAction:(UIButton *)sender {
    YQRegistViewController *registVc = [YQRegistViewController new];
    [self.navigationController pushViewController:registVc animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
